{extend name="layout/base"}

{block name="content"}
<div style="padding: 15px;">
    <form class="layui-form" lay-filter="form1">
        <div class="layui-form-item">
            <label class="layui-form-label">商户</label>
            <div class="layui-input-inline">
                <select lay-filter="name" name="openid">
                    {if ($Merchant== "") or ($Merchant==null) }
                    <option value="">无</option>
                    {else /}
                    {foreach $Merchant as $key=>$vo }
                    <option value="{$vo.openid}">{$vo.mername}</option>
                    {/foreach}
                    {/if}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分账接收方类型</label>
            <div class="layui-input-inline">
                <select name="type" lay-filter="accountType">
                    <option value="PERSONAL_OPENID" >个人</option>
                    <option value="MERCHANT_ID" >商户</option>
                </select>
            </div>
            <div class="layui-input-inline" id="person">
                <input type="text" name="name" class="layui-input" placeholder="">
            </div>
            <div class="layui-input-inline" id="merchant">
                <input type="text" name="meichantNO" class="layui-input" placeholder="请输入商户唯一ID">
            </div>  
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分账金额类型</label>
            <div class="layui-input-inline">
                <select name="bill_type" lay-filter="ledger">
                    <option value="2">按比例</option>
                    <option value="-1">按金额</option>
                </select>                     
            </div>
            <div id="ratio">
                <div class="layui-input-inline">
                    <input type="number" name="ratio" class="layui-input" placeholder="请输入分账比例" lay-verify="ratio">
                </div>
                <div class="layui-form-mid layui-word-aux">输入的比例数满足大于0小于0.3</div>
            </div>           
            <div class="layui-input-inline" id="money">
                <input type="text" name="amount" class="layui-input" placeholder="请输入分账金额">
            </div>   
        </div>
        <div class="layui-form-item">
            <div  style="margin-left: 110px;">
                <button class="layui-btn" lay-submit lay-filter="submitadd">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
            
        </div>
    </form>
</div>
<script>
layui.use(['jquery','form'],function(){
    var $ = layui.jquery,
        form = layui.form;

    $('#person').hide();
    $('#merchant').hide()
    $('#ratio').hide();
    $('#money').hide()
    form.on('select(name)', function(data){        
        form.val("form1", {"openid": data.value});
    }); 
    form.on('select(accountType)', function(data){
        if(data.value =='PERSONAL_OPENID'){
            $('#person').show();
            $('#person').children("input").attr('placeholder','请输入真实姓名');
            $('#merchant').hide()
        }else if(data.value =='MERCHANT_ID'){
            $('#person').show();
            $('#person').children("input").attr('placeholder','请输入商户全称');
            $('#merchant').show()
        }else{
            $('#person').hide();
            $('#merchant').hide()
        }
    }); 
    form.on('select(ledger)',function(data){
        if(data.value ==2){
            $('#ratio').show();
            $('#money').hide()
        }else if(data.value ==-1){
            $('#ratio').hide();
            $('#money').show()
        }else{
            $('#ratio').hide();
            $('#money').hide()
        }
    }) 
    // form.verify({
    //     ratio:function(value){
    //         if(value<=0 || value>=0.3){
    //             return '请输入大于0小于0.3的数字'
    //         }
    //     }
    // })
    form.on('submit(submitadd)', function(data){
        $.ajax({
            type:'post',
            data:data.field,
            url:'addreceiver',
            success:function(res){
                if(res.code == 0){
                    layer.msg(res.msg);
                    //var index = parent.layer.getFrameIndex(window.name);
                    //parent.layui.table.reload('demo');
                    //parent.layer.close(index);
                }else{
                    console.log(res.msg)
                }
                
            }
        })
        return false; 
    }); 
})
    
</script>
{/block}